package org.csu.sei.common;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.csu.sei.common.BaseConstant.ErrorCode;

//import org.json.Object;


public class ReturnJson {

    int status;
    int code;
    String msg;
    Object data;

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public ReturnJson(String msg){
        this.status = 200;
        this.msg = msg;
    }

    public ReturnJson(int status, int code, String msg, Object data) {
        this.status = status;
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public ReturnJson(int status, int code, String msg) {
        this.status = status;
        this.code = code;
        this.msg = msg;
    }

    public ReturnJson(int status, Object data) {
        this.status = status;
        this.data = data;
    }

    public ReturnJson(ErrorCode errorCode) {
        this.code = errorCode.getCode();
        this.msg = errorCode.getDescription();
    }

    public ReturnJson(Object data) {
        this.status = 200;
        this.data = data;
    }

    public static JSONObject successRes(JSONObject data){
        JSONObject data1 = JSON.parseObject(data.toString());
        ReturnJson returnJson = new ReturnJson(data1);
        return JSON.parseObject(JSON.toJSONString(returnJson));
    }


    public static JSONObject defaultFailureRes(ErrorCode code){
        ReturnJson returnJson = new ReturnJson(200,code.getCode(),code.getDescription());
        return JSON.parseObject(JSON.toJSONString(returnJson));
    }

    public static JSONObject failureResWithMsg(ErrorCode code,String msg){
        ReturnJson returnJson = new ReturnJson(200,code.getCode(),msg);
        return JSON.parseObject(JSON.toJSONString(returnJson));
    }

    public static JSONObject ackWithMsg(String msg){
        ReturnJson returnJson = new ReturnJson(msg);
        return JSON.parseObject(JSON.toJSONString(returnJson));
    }

}
